# 修改文件内容
# 有文件aaa.txt内容是Python,把c.txt中的Python修改为Java
file = open(r"e:\aaa.txt", "r")
txt = file.read()
s = txt.replace("Python", "java")
file.close() # 必须关闭
file = open(r"e:\aaa.txt", "w")
file.write(s)
file.close()